package com.cn.wanxi.thread;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class MyTimer {
    public static void main(String[] args) throws ParseException {
        final int[] a = {0};
        Timer timer = new Timer();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        simpleDateFormat.parse("2020-8-28 10:16:00");
        timer.schedule(new TimerTask() {
            @Override
            public void run() {

                System.out.println(a[0]++);
                if (a[0] == 6) {
//                    System.out.println("定时器取消");
//                    timer.cancel();
                }
            }
        },simpleDateFormat.parse("2020-8-28 10:16:00"), 1000);
    }
}
